package com.share.lottery.activity.fans;

import java.util.ArrayList;
import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.lidroid.xutils.BitmapUtils;
import com.share.lottery.R;
import com.share.lottery.model.Rqb;
import com.share.lottery.model.User;

public class Fansdapter extends BaseAdapter {
	private BitmapUtils bitmapUtils;
	private List<Rqb> userList = new ArrayList<Rqb>();
	private  Context context;
	public Fansdapter(Context context) {
		this.context = context;
		if (bitmapUtils == null) {
			bitmapUtils = new BitmapUtils(context);
		}
	}
	public int getCount() {

		return userList.size();
	}


	public Rqb getItem(int arg0) {

		return userList.get(arg0);
	}


	public long getItemId(int arg0) {

		return arg0;
	}


	public View getView(int position, View convertView, ViewGroup arg2) {
		Rqb user = userList.get(position);
		ViewHolder viewHolder = null;
		if (convertView == null) {
			convertView = LayoutInflater.from(context).inflate(
					R.layout.rqb_item, null);
			viewHolder = new ViewHolder();

			viewHolder.imgUserHead = (ImageView) convertView.findViewById(R.id.img_head);
			//			viewHolder.imgUserHead = (ImageView) convertView.findViewById(R.id.img_head);
			viewHolder.imgSex = (ImageView) convertView.findViewById(R.id.img_sex);
			viewHolder.tvQM = (TextView) convertView.findViewById(R.id.tv_gxqm);
			viewHolder.tvName = (TextView) convertView.findViewById(R.id.tv_name);
			convertView.setTag(viewHolder);
		} else {
			viewHolder = (ViewHolder) convertView.getTag();
		}
		/*	if (User.MALE_F.equals(user.getSex())) {
			viewHolder.imgSex.setImageResource(R.drawable.naoli_female);
		}else if(User.MALE_M.equals(user.getSex())){
			viewHolder.imgSex.setImageResource(R.drawable.naoli_male);
		}*/
		String amount = user.getReadAmount();

		viewHolder.tvName.setText(user.getNickname());

		viewHolder.tvQM.setText(user.getSignature());

		//		bitmapUtils.display(viewHolder.imgUserHead, user.getAvatar(),
		//				new BitmapLoadCallBack<View>() {
		//
		//				
		//					public void onLoadCompleted(View container, String uri,
		//							Bitmap bitmap, BitmapDisplayConfig config,
		//							BitmapLoadFrom from) {
		//						// TODO Auto-generated method stub
		//						if (bitmap != null) {
		//							((ImageView) container)
		//									.setImageBitmap(getRoundBitmap
		//											.toRoundBitmap(bitmap));
		//						}
		//					}
		//
		//					@Override
		//					public void onLoadFailed(View container, String uri,
		//							Drawable drawable) {
		//					
		//						((ImageView) container)
		//								.setImageResource(R.drawable.contact_head);
		//					}
		//				});
		return convertView;
	}
	class ViewHolder {
		ImageView imgUserHead;// 头像
		ImageView imgSex;//性别
		TextView tvName;//姓名
		TextView tvQM;//个性签名
	}

	/**
	 * 添加数据
	 * 
	 * @param rows
	 */
	public void addDatas(List<Rqb> rows) {

		userList.addAll(rows);

		notifyDataSetChanged();
	}

	/**
	 * 清空数据
	 */
	public void clearDatas() {

		userList.clear();
		notifyDataSetChanged();
	}

}
